package leetcode.code1779;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int nearestValidPoint(int x, int y, int[][] points) {
		int min = Integer.MAX_VALUE;
		int ans = -1;
		for (int i = 0; i < points.length; i++) {
			int[] point = points[i];
			int a = point[0], b = point[1];
			if (a == x || b == y) {
				int dist = Math.abs(a - x) + Math.abs(b - y);
				if (dist < min) {
					ans = i;
					min = dist;
				}
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
